{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7bbfbe10",
   "metadata": {},
   "outputs": [],
   "source": [
    "字典可以存储任意对象。字典是以**键值对**的形式创建的<u>{'key':'value'}</u>利用**大括号**包裹，和list一样，支持对数据的添加、修改、删除\n",
    "\n",
    "访问值的安全方式：get方法\n",
    "在不确定字典是否存在某一个值而又想获取其值时，可以使用get方法，还可以设置默认值\n",
    "\n",
    "*注意：1.字典的键（key）不能重复，值（value）可以重复\n",
    "        2.字典的键（key）只能是不可变类型，如数字、字符串、元组*\n",
    "        \n",
    " 特点：1.不是序列类型，没有下标的概念，是一个无序的键值集合，是内置的高级数据类型\n",
    "         2.用{}来表示字典对象，每个键值对用逗号分隔\n",
    "         3.键必须是不可变的类型【元组、字符串】,值\n",
    "         可以是任意类型\n",
    "         4.每个键必定是唯一的，如果存在重复的键，后者会覆盖前者\n",
    "         \n",
    "### 1.[]添加、修改键值对\n",
    "例：\n",
    "```\n",
    "dict={} #空字典\n",
    "dict['name']='147'\n",
    "print(dict)\n",
    "```\n",
    "运行结果为打印出{'name':'147'}\n",
    "### 2.len()\n",
    "用来计算字典中一共有几个键值对，用法与列表中的相同\n",
    "### 3.如何通过键获取对应的值\n",
    "例：\n",
    "```\n",
    "dict={'name':'147'}\n",
    "print(dict['name'])\n",
    "```\n",
    "运行结果为打印出147\n",
    "### 4.keys（）\n",
    "获取所有的键，例：\n",
    "```\n",
    "dict={'name':'147','age':7}\n",
    "print(dict.keys())\n",
    "```\n",
    "运行结果为打印出dict.keys(['name','age'])\n",
    "### 5.values()\n",
    "获取所有的值，使用方法与keys（）相同\n",
    "### 6.items()\n",
    "获取所有的键和值（以列表形式），使用方法与keys（）相同\n",
    "### 7.updat（）\n",
    "添加或更新键值对，使用方法：字典名.updat({'height':'180'})\n",
    "### 8.del\n",
    "删除字典中的键值对，使用方法：\n",
    "del 字典名['键']\n",
    "### 9.pop（）\n",
    "取出某一键值对，取出的键值对可另外使用"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
